<template>
  <div id="login">
    <div class="contain">
      <table>
        <tr>
          <td>账号</td>
          <td>
            <el-input placeholder="请输入账号" v-model="account" clearable>
            </el-input>
          </td>
        </tr>
        <tr>
          <td>密码</td>
          <td>
            <el-input placeholder="请输入密码" v-model="password" show-password></el-input>
          </td>
        </tr>
        <tr>
          <td colspan="2" style="text-align: center">
            <el-button type="primary" size="small" @click="startLogin">登录</el-button>
            <el-button type="warning" size="small">重置</el-button>
          </td>
        </tr>
      </table>
    </div>
  </div>
</template>

<script setup lang="ts">
import api from '@/api';
import { formItem } from '@/api/modules/adminList';
import { ElMessage } from 'element-plus';
import { ref } from 'vue';
import { useRouter } from 'vue-router';
const router = useRouter();
const account=ref("")
const password=ref("")
const startLogin = async () => {
  const res = await api.adminList.login({
    account:account.value,
    password:password.value
  })
  account.value=''
  password.value=""
  if (res.code == 200) {
    // console.log(res);
    ElMessage.success("恭喜你成功")
    localStorage.user_token = (res as any).token
    router.replace("/")
  } else {
    ElMessage.error(res.message)
  }
}

</script>

<style scoped lang="scss">
#login {
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #0873ff;

  .contain {
    width: 550px;

    table {
      margin: 0 auto;
      width: 350px;
      height: 230px;
      font-size: 14px;
      color: white;

      tr {
        td:first-child {
          text-align: right;
        }

        td:last-child {
          text-align: right;
        }

        td {
          .el-input {
            width: 90%;
          }
        }
      }
    }
  }
}
</style>